﻿@model CategoryNavigationModel
@using Nop.Web.Models.Catalog;

@helper RenderFirstCategoryLine(CategoryNavigationModel.CategoryModel category, int randomint)
{
        if (Model.StoreId > 1)
        {
            <a href="search?Cid=@category.Id" class="category-hover">@category.Name
                @if (category.SubCategories.Count > 0)
                {
                    <div class="icon-activearrow icon"></div>
                }
                @if (category.NumberOfProducts.HasValue)
                {
                    <text> (@(category.NumberOfProducts.Value))</text>
                }
            </a>
        }
        else
        {
            <a href="search?Cid=@category.Id"  class="category-hover">@category.Name
                @if (category.SubCategories.Count > 0)
                {
                    <div class="icon-activearrow icon"></div>
                }
                @if (category.NumberOfProducts.HasValue)
                {
                    <text> (@(category.NumberOfProducts.Value))</text>
                }
                <div class="icon"></div>
            </a>
        }
        @RenderFirstSubCategoryLine(category, randomint)
   
}
@helper RenderFirstSubCategoryLine(CategoryNavigationModel.CategoryModel category, int randomint)
{
    if (category.SubCategories.Count > 0)
    {
        <div class="subcategory-hover">
            <div class="subcategory-wrapper">
                @{
                    
                    if (randomint == 1) {
                        <img src="/subsites/commerce/themes/SpotsHUB/Content/images/placeholder-category-img1.png" />
                    } else if (randomint == 2) {
                        <img src="/subsites/commerce/themes/SpotsHUB/Content/images/placeholder-category-img2.png" />
                    } else if (randomint == 3) {
                        <img src="/subsites/commerce/themes/SpotsHUB/Content/images/placeholder-category-img3.png" />
                    } else {
                        <img src="/subsites/commerce/themes/SpotsHUB/Content/images/placeholder-category-img4.png" />
                    }
                }
                <h3>@category.Name</h3>
                <ul class="subcategories">
                @foreach (var subCategory in category.SubCategories)
                {
                    <li>
                    @RenderCategoryLine(subCategory)
                    </li>
                }
                </ul>
            </div>
        </div>
    }

}

@helper RenderSubCategoryLine(CategoryNavigationModel.CategoryModel category)
{
    
        if (category.SubCategories.Count > 0)
        {
            
            foreach (var subCategory in category.SubCategories)
            {

                    <li>
                        @RenderCategoryLine(subCategory)
                    </li>

            }
        }
    
}
@helper RenderCategoryLine(CategoryNavigationModel.CategoryModel category)
{
    
        if (Model.StoreId > 1)
        {
            
            <a href="@Url.RouteUrl("PerStoreCategory", new { SeName = category.SeName, categoryId = category.Id, storeId = Model.StoreId })">@category.Name</a>
            
        }
        else
        {
            <a href="@Url.RouteUrl("Category", new { SeName = category.SeName })">@category.Name
                @if (category.NumberOfProducts.HasValue)
                {
                    <text> (@(category.NumberOfProducts.Value))</text>
                }
            </a>
        }

        @RenderSubCategoryLine(category)
}

@if (Model.Categories.Count > 0)
{
    <li class="left-menu-category-item">
        <a class="title category-hover" href="/commerce">
            <strong>@T("Common.Home")</strong>
        </a>
        <div class="subcategory-hover">
            <div class="subcategory-wrapper">
                <ul class="subcategories all-subcategories">
                    @foreach (var category in Model.Categories)
                    {
                        @RenderSubCategoryLine(category)
                    }
                </ul>
            </div>
        </div>
    </li>
    
    Random random = new Random();
    int randomint = 0;
    
    foreach (var category in Model.Categories)
    {
        randomint = random.Next(0, 100) % 4;
        <li class="left-menu-category-item @(category.Id == Model.CurrentCategoryId ? "active" : "inactive")">
            @RenderFirstCategoryLine(category, randomint)
        </li>
    }

    
}
